<template>
    <div class="allresume">
        <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                @selection-change="handleSelectionChange"
                style="width: 100%">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column
                    prop="resumeName"
                    label="姓名">
            </el-table-column>
            <el-table-column
                    prop="resumeSex"
                    label="性别">
            </el-table-column>
            <el-table-column
                    prop="resumeBirth"
                    label="出生年月"
                    width="100"
                    :formatter="dateFormatter">
            </el-table-column>
            <el-table-column
                    prop="resumeAddress"
                    label="现居住地">
            </el-table-column>
            <el-table-column
                    prop="resumeEdu"
                    label="学历">
            </el-table-column>
            <el-table-column
                    prop="resumeExpr"
                    label="经验">
            </el-table-column>
            <el-table-column
                    prop="resumePhone"
                    width="110"
                    label="手机">
            </el-table-column>
            <el-table-column
                    prop="resumeEmail"
                    width="150"
                    label="邮箱">
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="100"
                    fixed="right"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
    export default {
        name: 'allresume',
        data() {
            return {
                tableData: []
            }
        },
        methods: {
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            dateFormatter (row) {
                let datetime = row.resumeBirth;
                if (datetime) {
                    datetime = new Date(datetime);
                    let y = datetime.getFullYear() + '-';
                    let mon = datetime.getMonth() + 1 + '-';
                    let d = datetime.getDate();
                    return y + mon + d;
                }
                return ''
            },
            handleDelete(index, row) {
                this.$confirm('检测到未保存的内容，是否在离开页面前保存修改？', '确认信息', {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '删除',
                    cancelButtonText: '放弃修改'
                })
                    .then(() => {
                        var params = new URLSearchParams();
                        params.append('resumeid', row.resumeId);
                        this.axios.post('http://localhost:8001/compReResume/deleteone', params).then((res) => {
                            console.log(res.data.msg)
                            if (res.data.status === 200) {
                                this.$router.go(0)//刷新页面
                                this.$message({
                                    showClose: true,
                                    type: 'success',
                                    message: res.data.msg,
                                });
                            } else {
                                this.$message({
                                    showClose: true,
                                    message: res.data.msg,
                                    type: 'error'
                                });
                            }
                        })
                    })
                    .catch(action => {
                        this.$message({
                            type: 'info',
                            message: action === 'cancel'
                                ? '放弃保存并离开页面'
                                : '停留在当前页面'
                        })
                    });
            },
        },
        mounted() {
            var params = new URLSearchParams();
            params.append('compid', this.$store.state.company)
            this.axios.post('http://localhost:8001/compReResume/getResume', params).then((res) => {
                this.tableData = res.data
            }).catch((err) => {
                console.log('error' + err);
            })
        },
    }
</script>
